#include <iostream>

class Solution {
public:
    int reverse(int x) {
        int rev = 0;
        while (x != 0) {
            int pop = x % 10;
            x /= 10;
            if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7) || rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)) 
                return 0;

            rev = rev * 10 + pop;
        }
        return rev;
    }
};

// 测试正数
void test01() {
    std::cout << "test01" << std::endl;
    Solution obj;
    int input = 123;
    std::cout << "input:" << input << std::endl;
    int re = obj.reverse(input);
    std::cout << "result:" << re << std::endl;
}

// 测试负数
void test02() {
    std::cout << "test02" << std::endl;
    Solution obj;
    int input = -123;
    std::cout << "input:" << input << std::endl;
    int re = obj.reverse(input);
    std::cout << "result:" << re << std::endl;
}

// 测试是否会溢出
void test03() {
    std::cout << "test03" << std::endl;
    Solution obj;
    int input = 2147483648;
    std::cout << "input:" << input << std::endl;
    int re = obj.reverse(input);
    std::cout << "result:" << re << std::endl;
}


int main() {
    test01();
    test02();
    test03();
    return 0;
}